# -*- coding: utf-8 -*-
"""
Example: Using ZhipuAI API in UC System
"""

# Method 1: Use the configuration module
from zhipu_config_clean import get_zhipu_client

def analyze_medical_image(image_description):
    """Example function for medical image analysis"""
    client = get_zhipu_client()

    prompt = f"""
    As a medical AI assistant, please analyze the following endoscopic image description:

    {image_description}

    Provide a brief assessment for UCEIS scoring including:
    1. Vascular pattern observations
    2. Bleeding indicators
    3. Ulcer presence
    """

    response = client.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=1000,
        messages=[{"role": "user", "content": prompt}]
    )

    return response.content[0].text

# Method 2: Use environment variables (after running setup_zhipu_env.bat)
import anthropic
import os

def get_client_from_env():
    """Get client from environment variables"""
    return anthropic.Anthropic(
        api_key=os.getenv("ANTHROPIC_AUTH_TOKEN", "d997a0d82859497ca57bf53cc12ccc2e.i9lC4WUDHX977cXx"),
        base_url=os.getenv("ANTHROPIC_BASE_URL", "https://api.z.ai/api/anthropic")
    )

# Method 3: Direct initialization
def get_client_direct():
    """Direct client initialization"""
    return anthropic.Anthropic(
        api_key="d997a0d82859497ca57bf53cc12ccc2e.i9lC4WUDHX977cXx",
        base_url="https://api.z.ai/api/anthropic"
    )

# Test all methods
if __name__ == "__main__":
    print("Testing different connection methods...")

    # Method 1 test
    print("\n1. Using config module:")
    try:
        client1 = get_zhipu_client()
        response = client1.messages.create(
            model="claude-3-5-sonnet-20241022",
            max_tokens=50,
            messages=[{"role": "user", "content": "Say 'Method 1 works!' in English."}]
        )
        print(f"   Response: {response.content[0].text}")
    except Exception as e:
        print(f"   Error: {e}")

    # Method 2 test
    print("\n2. Using environment variables:")
    try:
        client2 = get_client_from_env()
        response = client2.messages.create(
            model="claude-3-5-sonnet-20241022",
            max_tokens=50,
            messages=[{"role": "user", "content": "Say 'Method 2 works!' in English."}]
        )
        print(f"   Response: {response.content[0].text}")
    except Exception as e:
        print(f"   Error: {e}")

    # Method 3 test
    print("\n3. Using direct initialization:")
    try:
        client3 = get_client_direct()
        response = client3.messages.create(
            model="claude-3-5-sonnet-20241022",
            max_tokens=50,
            messages=[{"role": "user", "content": "Say 'Method 3 works!' in English."}]
        )
        print(f"   Response: {response.content[0].text}")
    except Exception as e:
        print(f"   Error: {e}")